package com.zbest.common.lang.base;

import java.io.Serializable;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import com.zbest.common.lang.enums.BizCode;
import com.zbest.common.lang.util.CoreSystemUtils;

/**
 * 服务调用返回值基类<br/>
 *
 * Created by wu.charles on 2014/12/10.
 */
public abstract class AbstractResponse extends AbstractModel implements Serializable {
    private static final long serialVersionUID = 9132233374292213699L;

    /**
     * 服务调用运行结果编码<br/>
     *
     */
    private BizCode           code             = null;

    /**
     * 服务调用描述信息<br/>
     *
     */
    private String            message          = null;

    public AbstractResponse() {
        setServerIp(CoreSystemUtils.localIp());
        setServerHostName(CoreSystemUtils.localHostName());
    }

    /**
     * Getter method for property <tt>code</tt>.
     * 
     * @return property value of code
     */
    public BizCode getCode() {
        return code;
    }

    /**
     * Setter method for property <tt>code</tt>.
     * 
     * @param code value to be assigned to property code
     */
    public void setCode(BizCode code) {
        this.code = code;
    }

    /**
     * 返回服务调用描述信息<br/>
     *
     * @return
     */
    public String getMessage() {
        return message;
    }

    /**
     * 设置服务调用描述信息<br/>
     *
     * @param message
     */
    public void setMessage(String message) {
        this.message = message;
    }

    public boolean isSuccess() {
        return this.code == BizCode.SUCCESS;
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
    }
}
